package ngames.com.sushitv.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;

import ngames.com.sushitv.R;
import ngames.com.sushitv.base.BaseListAdapter;
import ngames.com.sushitv.entity.ItemVideo;

/**
 * Created by Fearless on 2016/6/26.
 */
public class VideoRankAdapter extends BaseListAdapter<ItemVideo> {

    public VideoRankAdapter(Context context, ArrayList<ItemVideo> list) {
        super(context, list);

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new VideoRankHolder(mInflater.inflate(R.layout.item_videorank_list, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        VideoRankHolder videoRankHolder = (VideoRankHolder) holder;
        videoRankHolder.setData(position);
    }


    class VideoRankHolder extends RecyclerView.ViewHolder {
        TextView titleTxt, danmuTxt, playtxt;
        ImageView imageView;

        public VideoRankHolder(View itemView) {
            super(itemView);
            titleTxt = (TextView) itemView.findViewById(R.id.text_videorank_title);
            danmuTxt = (TextView) itemView.findViewById(R.id.text_videorank_danmu_count);
            playtxt = (TextView) itemView.findViewById(R.id.text_videorank_play_count);
            imageView = (ImageView) itemView.findViewById(R.id.relative_videorank_img);
        }

        public void setData(int position) {
            ItemVideo itemVideo = getItem(position);
            titleTxt.setText(itemVideo.getTitle());
            danmuTxt.setText(itemVideo.getDanmuCount());
            playtxt.setText(itemVideo.getPlayCount());
            //imageView.setText(itemVideo.getTitle());
            DisplayImageOptions options = new DisplayImageOptions.Builder()
                    /*.showStubImage(R.drawable.image_is_loading)            // 设置图片下载期间显示的图片
                    .showImageForEmptyUri(R.drawable.image_loading_failed)    // 设置图片Uri为空或是错误的时候显示的图片
                    .showImageOnFail(R.drawable.image_loading_failed)        // 设置图片加载或解码过程中发生错误显示的图片*/
                    .cacheInMemory(true)                        // 设置下载的图片是否缓存在内存中
                    .cacheOnDisc(true)                            // 设置下载的图片是否缓存在SD卡中
                    .build();
            String workerImgStr = itemVideo.getCover();
            ImageLoader.getInstance().displayImage(workerImgStr, imageView, options);// 创建配置过得DisplayImageOption对象
        }
    }
}
